package hci.drummer;

import hci.drummer.command.Command;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.util.Log;

public class SensorListener implements SensorEventListener{

	private CommandPusher pusher;
	public SensorListener(CommandPusher pusher){
		this.pusher = pusher;
	}
	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		Log.d("Drummer", "accuracy changed");
	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		synchronized (this) {
			float[] values = event.values;
			Command command = new Command(event.sensor.getType());
			command.setData(values[0], values[1], values[2]);
			this.pusher.pushCommand(command);
		}
	}

}
